import pygame
from pygame.locals import *
import sys
from test2_settings import Settings
from test2_ship import Ship

# 侧面射击：编写一个游戏，将一艘飞船放在屏幕左边，
# 并允许玩家上下移动飞船。在玩家按空格键时，
# 让飞船发射一颗在屏幕中向右穿行的子弹，
# 并在子弹离开屏幕而消失后将其删除。

def run_game():
    # 初始化游戏
    pygame.init()

    # 创建设置对象
    ai_setting = Settings()

#     创建屏幕窗口
    screen = pygame.display.set_mode((ai_setting.screen_width,ai_setting.screen_height))

#     设置窗口标题
    pygame.display.set_caption("测试上下移动飞船游戏")

    # 创建一艘飞船
    ship = Ship(screen)

    while True:
        # 监听键盘事件
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYUP:
                # 抬起按键
                if event.key == pygame.K_UP:
                    print(event)
                elif event.key == pygame.K_DOWN:
                    print(event)
            elif event.type == pygame.KEYDOWN:
                # 按下按键
                if event.key == pygame.K_UP:
                    print(event)
                elif event.key == pygame.K_DOWN:
                    print(event)

        # 每次循环重绘屏幕
        screen.fill(ai_setting.bg_color)


        ship.blitme()


        # 让屏幕可见
        pygame.display.flip()


run_game()